import 'package:chaos_flutter3/app/consts/ImageUrlString.dart';
import 'package:chaos_flutter3/app/dtos/ZyyShareDoc.dart';
import 'package:chaos_flutter3/chaos/Data.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class InfoTab extends HookWidget {
  const InfoTab({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final listData = useState([]);

    load() async {
      listData.value = ZyyShareDoc.toList(await Data().list('zyyShareDoc'));
    }

    useEffect(() {
      load();
    }, []);

    buildHead() => Padding(
          padding: const EdgeInsets.fromLTRB(16, 42.5, 21.5, 20.5),
          child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: const [Text("头部")]),
        );

    void handleTap(id) {
      Navigator.pushNamed(context, "info", arguments: id);
    }

    buildInfos() => Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: listData.value.isNotEmpty
            ? listData.value
                .map((item) => Padding(
                      padding: const EdgeInsets.fromLTRB(16, 42.5, 21.5, 20.5),
                      child: GestureDetector(
                          onTap: ()=>handleTap(item.id),
                          child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(item.username,
                                    textAlign: TextAlign.center,
                                    overflow: TextOverflow.ellipsis,
                                    style: const TextStyle(
                                        fontStyle: FontStyle.italic))
                              ])),
                    ))
                .toList()
            : [const Text('暂无数据')]);

    return SingleChildScrollView(
        child: Column(
      children: [buildHead(), buildInfos()],
    ));
  }
}
